package Method;

/**
 * @author 王艺锡
 * @version 1.0
 * 如何将线程设置为守护线程
 */
public class ThreadMethod03 {
    public static void main(String[] args) throws InterruptedException {
        MyDaemon myDaemon = new MyDaemon();
        //设置子线程myDaemon为守护线程，主线程结束，守护线程随之结束
        myDaemon.setDaemon(true);
        myDaemon.start();
        for (int i = 0; i < 10; i++) {
            System.out.println("奇迹行者还在刷野!");
            Thread.sleep(1000);
        }
    }
}

class MyDaemon extends Thread {
    @Override
    public void run() {
        while (true) {
            System.out.println("他妈的家都没了还在这嗨~你好~");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
